-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto: better error message when calling digest twice on a hash #6042
Conversation
It would be nice to have same for Hmac. |
I'd probably want to put that into a different pull request |
@@ -3735,7 +3739,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) { | |||
|
|||
EVP_DigestFinal_ex(&hash->mdctx_, md_value, &md_len); | |||
EVP_MD_CTX_cleanup(&hash->mdctx_); | |||
hash->initialised_ = false; | |||
hash -> finalized_ = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the spaces before and after the arrow should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Perhaps we should also be inserting a similar check for |
d3f1fea
to
735ac30
Compare
@@ -3722,6 +3723,9 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) { | |||
if (!hash->initialised_) { | |||
return env->ThrowError("Not initialized"); | |||
} | |||
if (hash->finalized_) { | |||
return env->ThrowError("Digest Already Called"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason for the capitalization here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point fixing
why not use only |
3b61487
to
ba02203
Compare
@fanatid because there could be some way that a bug could cause the hash to be in an inconsistent state and better safe then sorry |
@calvinmetcalf I think that this line never will be reached because you add error throwing |
assert.throws(function() { | ||
h3.digest(); | ||
}, | ||
/Digest Already Called/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalization should be changed here too.
I think an additional test for |
3cda16d
to
4d5a452
Compare
LGTM pending CI |
@calvinmetcalf could you answer for my first question?
|
h3.digest(); | ||
}, | ||
/Digest already called/); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linter is complaining about trailing spaces on this line
@fanatid woops was cut off replying via email, the initialized would only ever be false if for some reason the hash wasn't initialized, which probably not be possible as it is currently set up, but we don't really loose much testing for it and we will prevent problems down the line if some other change allows it to get into a weird state. |
calling digest or update on a hash object after digest has been called now gives a topical error message instead of an error message saying that the hash failed to initialize.
4d5a452
to
2cb82d2
Compare
@mscdex ... ping.. looks like this was updated. PTAL |
CI is green |
LGTM |
calling digest or update on a hash object after digest has been called now gives a topical error message instead of an error message saying that the hash failed to initialize. PR-URL: #6042 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 1d9451b |
calling digest or update on a hash object after digest has been called now gives a topical error message instead of an error message saying that the hash failed to initialize. PR-URL: nodejs#6042 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com>
calling digest or update on a hash object after digest has been called now gives a topical error message instead of an error message saying that the hash failed to initialize. PR-URL: #6042 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Pull Request check-list
Please make sure to review and check all of these items:
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass withthis change (including linting)?
I'm getting an error on the test-tick-processor test, seems unrelated
test (or a benchmark) included?
existing APIs, or introduces new ones)?
NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Affected core subsystem(s)
Please provide affected core subsystem(s) (like buffer, cluster, crypto, etc)
Description of change
calling digest twice on a hash used to give an unhelpful error about the hash not being initialized, this fixes that